package utils

import utils.data.{CNode, CTree}

trait CValuable[T]
{
    def value(t:T):Option[String]
}

object CHTMLTree
{
    def apply[T <: CNode[T] : CValuable](tree:CTree[T], file:String)
    {
        val vlbl = implicitly[CValuable[T]]
        val strBldr = new StringBuilder
        def walk(node:T, level:Int = 0)
        {
            (vlbl value node) foreach (v => strBldr.append(" ----- " concat v))
            strBldr.append("<ul style='LIST-STYLE-TYPE : NONE; padding : 0; margin-left : 100px'>")
            tree children node foreach (n =>
            {
                strBldr.append("<li>")
                walk(n, level + 1)
                strBldr.append("</li>")
            })
            strBldr.append("</ul>")
        }
        walk(tree.root)
        CFile.write(file, strBldr.toString)
    }
}
